#!coding=utf-8
import threading
import queue

# 创建队列
queue = queue.Queue()

# 生产者线程
def producer():
    for i in range(5):
        print(f"Producing item {i}")
        queue.put(i)

# 消费者线程
def consumer():
    while True:
        item = queue.get()
        print(f"Consuming item {item}")
        queue.task_done()

# 创建并启动线程
producer_thread = threading.Thread(target=producer)
consumer_thread = threading.Thread(target=consumer)

producer_thread.start()
consumer_thread.start()

# 等待生产者完成
producer_thread.join()

# 等待队列清空
queue.join()

print("All tasks are done.")
